/****************************************************************************
 * 2025.4 APU
 ****************************************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Linq;
using QAssetBundle;

namespace QFramework.Example
{
	public partial class ExpUpgradePanel : UIElement, IController
	{
		private void Awake()
		{
			OnAddAblilty();
			// var objBox = transform.GetChild(1).GetChild(0);
			// var expSystem = this.GetSystem<ExpUpgradeSystem>();
			// foreach (var item in expSystem.list_ExpUpgradeItems.Where(item => item.UpgradeCondition()))
			// {
			// 	BtnAddSemplaAbilityAtk.InstantiateWithParent(objBox)
			// 	.Self((self) =>
			// 	{
			// 		var tempItem = item;
			// 		var _self = self;
			// 		self.GetComponentInChildren<Text>().text = tempItem.Description;
			// 		self.onClick.AddListener(() =>
			// 		{
			// 			tempItem.Upgrade(tempItem);

			// 			this.Hide();
			// 		});
			// 	})
			// 	.Show();
			// }
		}

		protected override void OnShow()
		{
			base.OnShow();
			//OnRefresh();
		}

		protected override void OnBeforeDestroy()
		{

		}

		private void OnRefresh()
		{
			var objBox = transform.GetChild(1).GetChild(0);
			//objBox.DestroyChildren();

			var expSystem = this.GetSystem<ExpUpgradeSystem>();

			foreach (var item in expSystem.list_ExpUpgradeItems.Where(item => item.UpgradeCondition()))
			{
				BtnAddSemplaAbilityAtk.InstantiateWithParent(objBox)
				.Self((self) =>
				{
					var tempItem = item;
					self.GetComponentInChildren<Text>().text = tempItem.Description;
					self.onClick.AddListener(() =>
					{
						tempItem.Upgrade(tempItem);
						this.Hide();
					});
				})
				.Show();
			}
		}

		/// <summary>
		/// 添加能力
		/// </summary>
		private void OnAddAblilty()
		{
			int atkLv = 1;
			int durLv = 1;
			//简单技能添加攻击力按钮侦听
			BtnAddSemplaAbilityAtk.onClick.AddListener(() =>
			{
				Time.timeScale = 1;
				AudioKit.PlaySound(Sfx.ABILITYLEVELUP);
				Global.SimpleAbilityAtk.Value++;
				atkLv++;
				BtnAddSemplaAbilityAtk.GetComponentInChildren<Text>().text = "升级 Sample Ability 攻击力 Lv" + atkLv.ToString();
				this.Hide();
			});

			BtnAddSemplaAbilityDuration.onClick.AddListener(() =>
			{
				Time.timeScale = 1;
				AudioKit.PlaySound(Sfx.ABILITYLEVELUP);
				Global.SimpleAbilityDuration.Value *= 0.8f;
				durLv++;
				BtnAddSemplaAbilityDuration.GetComponentInChildren<Text>().text = "升级 Sample Ability 间隔 Lv" + durLv.ToString();
				this.Hide();

			});
		}

		public IArchitecture GetArchitecture()
		{
			return Global.Interface;
		}
	}
}